package com.dgut.common.mapper;

import com.dgut.common.entity.CollectionOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dgut.common.param.OrderFormParam;
import com.dgut.common.result.OrderSevenDayData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zyq
 * @since 2022-03-13
 */
@Repository
public interface CollectionOrderMapper extends BaseMapper<CollectionOrder> {

    @Insert("insert into collection_order(remark, publish_time) values(#{param.remark}, #{param.publishTime}) ")
    int addBaseOrder(@Param("param") OrderFormParam param);

    @Update("update collection_order set state = 5,finish_time = now() where state = 0 and subscription_time < now()")
    int timeout();

    @Select("select count(*) as count, IFNULL(sum(IFNULL(amount, 0)), 0) as amount, IFNULL(sum(IFNULL(total_weight, 0)), 0) as weight from collection_order where date(create_time) = date(#{date})")
    OrderSevenDayData countByDate(Date date);

}
